
#import "../CAShared.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>


//ios
void ios_ShowShared(CAImage* imageName,int type)
{
    //创建UIImage
    CAImage::PixelFormat pixelFormat = imageName->getPixelFormat();
    
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    
    UIImage *newImage = NULL;
    CGImageRef imageRef = NULL;
    CGDataProviderRef provider = NULL;
    
    if (pixelFormat == CAImage::PixelFormat_RGBA8888 || pixelFormat == CAImage::PixelFormat_RGBA4444)
    {
        provider = CGDataProviderCreateWithData(NULL, imageName->getData(), 4*(imageName->getPixelsWide())*imageName->getPixelsHigh(), NULL);
        
        imageRef = CGImageCreate(imageName->getPixelsWide(), imageName->getPixelsHigh(), 8, 32, 4*(imageName->getPixelsWide()), colorSpaceRef, kCGBitmapByteOrderDefault, provider, NULL, NO, kCGRenderingIntentDefault);
        
        newImage = [UIImage imageWithCGImage:imageRef];
    }
    
    else
    {
        provider = CGDataProviderCreateWithData(NULL, imageName->getData(), 3*(imageName->getPixelsWide())*imageName->getPixelsHigh(), NULL);
        
        imageRef = CGImageCreate(imageName->getPixelsWide(), imageName->getPixelsHigh(), 8, 24, 3*(imageName->getPixelsWide()), colorSpaceRef, kCGBitmapByteOrderDefault, provider, NULL, NO, kCGRenderingIntentDefault);
        
        newImage = [UIImage imageWithCGImage:imageRef];
    }
    
    CFRelease(imageRef);
    CGColorSpaceRelease(colorSpaceRef);
    CGDataProviderRelease(provider);
    
    //创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    
    switch (type) {
        case WeChatFriends:
        {
            //定制微信好友的分享内容
            //[shareParams SSDKSetupWeChatParamsByText:nil title:nil url:[NSURL URLWithString:nil] thumbImage:nil image:[UIImage imageNamed:@"test.png"] musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatSession];

            //定制微信好友的分享内容
            [shareParams SSDKSetupWeChatParamsByText:nil title:nil url:[NSURL URLWithString:nil] thumbImage:nil image:[UIImage imageWithCGImage:imageRef] musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatSession];
            
            
            //进行分享
            [ShareSDK share:SSDKPlatformTypeWechat //传入分享的平台类型
                 parameters:shareParams
             onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
        }
            break;
            
            
        case Moments:
        {
            // 定制微信朋友圈的分享内容
            [shareParams SSDKSetupWeChatParamsByText:nil title:nil url:[NSURL URLWithString:nil] thumbImage:nil image:[UIImage imageWithCGImage:imageRef] musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatTimeline];
            
            //进行分享
            [ShareSDK share:SSDKPlatformSubTypeWechatTimeline //传入分享的平台类型
                 parameters:shareParams
             onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
        }
            break;
            
            
        case QQFriends:
        {
            
            // 定制QQ好友的分享内容
            [shareParams SSDKSetupQQParamsByText:nil title:nil url:[NSURL URLWithString:nil] thumbImage:nil image:[UIImage imageWithCGImage:imageRef] type:SSDKContentTypeImage forPlatformSubType:SSDKPlatformSubTypeQQFriend];
            
            //进行分享
            [ShareSDK share:SSDKPlatformTypeQQ //传入分享的平台类型
                 parameters:shareParams
             onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
        }
            break;
            
        case SinaWeibo:
        {
            
        }
            break;
            
        case QQZone:
        {
            // 定制QQ好友的分享内容
            [shareParams SSDKSetupQQParamsByText:@"Test" title:@"Test" url:[NSURL URLWithString:@"http://mob.com"] thumbImage:nil image:[UIImage imageWithCGImage:imageRef] type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeQZone];
            
            //进行分享
            [ShareSDK share:SSDKPlatformSubTypeQZone //传入分享的平台类型
                 parameters:shareParams
             onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
            
        }
            break;
            
        default:
            break;
            
    }

}


void ShowShared(const std::string &imageName,int type)
{
    //创建分享参数
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];

    switch (type) {
        case WeChatFriends:
        {
             //定制微信好友的分享内容
            [shareParams SSDKSetupWeChatParamsByText:nil title:nil url:[NSURL URLWithString:nil] thumbImage:nil image:[UIImage imageNamed:@"test.png"] musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatSession];
            
             //进行分享
            [ShareSDK share:SSDKPlatformTypeWechat //传入分享的平台类型
                     parameters:shareParams
                 onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
        }
        break;
        
            
        case Moments:
        {
            // 定制微信朋友圈的分享内容
            [shareParams SSDKSetupWeChatParamsByText:nil title:nil url:[NSURL URLWithString:nil] thumbImage:nil image:[UIImage imageNamed:@"test.png"] musicFileURL:nil extInfo:nil fileData:nil emoticonData:nil type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeWechatTimeline];
            
            //进行分享
            [ShareSDK share:SSDKPlatformSubTypeWechatTimeline //传入分享的平台类型
                     parameters:shareParams
                 onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
        }
        break;
           
            
        case QQFriends:
        {
         
            // 定制QQ好友的分享内容
            [shareParams SSDKSetupQQParamsByText:nil title:nil url:[NSURL URLWithString:nil] thumbImage:nil image:[UIImage imageNamed:@"test.png"] type:SSDKContentTypeImage forPlatformSubType:SSDKPlatformSubTypeQQFriend];

            //进行分享
            [ShareSDK share:SSDKPlatformTypeQQ //传入分享的平台类型
                         parameters:shareParams
                     onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
        }
        break;
            
        case SinaWeibo:
        {
            
        }
        break;
            
        case QQZone:
        {
            // 定制QQ好友的分享内容
            [shareParams SSDKSetupQQParamsByText:@"Test" title:@"Test" url:[NSURL URLWithString:@"http://mob.com"] thumbImage:nil image:[UIImage imageNamed:@"source_pro/indicator2.png"] type:SSDKContentTypeAuto forPlatformSubType:SSDKPlatformSubTypeQZone];
            
            //进行分享
            [ShareSDK share:SSDKPlatformSubTypeQZone //传入分享的平台类型
                 parameters:shareParams
             onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {}];
            
        }
        break;
            
        default:
            break;
    
    }
    
    
}
